package com.ht.controller;

import com.ht.data.Result;
import com.ht.domain.bo.TbJuniorBO;
import com.ht.domain.vo.TbDepartmentVO;
import com.ht.domain.vo.TbJuniorVO;
import com.ht.em.ResultEnum;
import com.ht.service.JuniorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("junior")
@Api
public class JuniorController {

    @Autowired
    private JuniorService juniorService;

    /**
     * 根据科室id查询下面对应的专科
     * @param departmentId
     * @return
     */
    @ApiOperation("根据科室id查询下面对应的专科")
    @PostMapping("findJuniorListByDepartmentId/{departmentId}")
    public Result findJuniorListByDepartmentId(@PathVariable("departmentId")Long departmentId){
        List<TbJuniorBO> juniorBOList = juniorService.findJuniorListByDepartmentId(departmentId);
        //判断是否查询到数据,如果没有数据返回状态码(未找到符合条件的数据)
        if (juniorBOList.size() <= 0){
            return Result.response(ResultEnum.QUERY_NULL);
        }
        //将bo类转成vo类返回数据到前台
        List<TbJuniorVO> juniorVOList = new ArrayList<>();
        juniorBOList.forEach((juniorBO) -> {
            TbJuniorVO juniorVO = new TbJuniorVO(juniorBO);
            juniorVOList.add(juniorVO);
        });
        return Result.OK().setData(juniorVOList);
    }
}
